package com.example.controller;

import com.example.common.result.Result;
import com.example.entity.dto.salesSlipDto;
import com.example.entity.yifei.Coptg;
import com.example.entity.yifei.Copth;
import com.example.service.CoptgService;
import com.example.service.SalesService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "销货单前端控制器")
@Slf4j
@RequestMapping("/api/Coptg")
public class CoptgController {

    @Resource
    private CoptgService coptgService;

    @Resource
    private SalesService salesService;

//    @ApiOperation("销货单单头列表分页查询")
//    @GetMapping("/queryIPage/{current}/{size}")
//    public Result<Map<String, Coptg>> queryIPage(@PathVariable Integer current, @PathVariable Integer size){
//        return this.coptgService.queryIPage(current,size);
//    }

    @ApiOperation("销货单单头列表分页查询")
    @GetMapping("/queryIPage/{current}/{size}")
    public Result<PageInfo<List<Coptg>>> queryIPage(@PathVariable Integer current, @PathVariable Integer size){
        return this.coptgService.queryIPage3(current,size);
    }

    @ApiOperation("销货单单身列表查询")
    @GetMapping("/queryList/{tg001}/{tg002}")
    public Result<List<Copth>> queryList(@PathVariable String tg001, @PathVariable String tg002){
        return this.coptgService.queryList(tg001,tg002);
    }

    @ApiOperation("生成销货单")
    @PutMapping("/salesSlip")
    public Result salesSlip(@RequestBody salesSlipDto salesSlipDto) throws UnknownHostException {
        Map<String,String> slips;
        if (salesSlipDto.getStatus().equals("Y")){
            slips = salesService.salesSlipByAdvice(salesSlipDto);
        }else{
            slips = salesService.salesSlipByOrder(salesSlipDto);
        }
        return Result.ok(slips);
    }

}
